package org.coody.gitee.fuzzer;

import java.text.MessageFormat;

import org.coody.gitee.entity.GiteeEntity;
import org.coody.gitee.exception.EmailRegisterException;
import org.coody.gitee.exception.FuzzerException;
import org.coody.gitee.fuzzer.iface.GiteeFuzzer;
import org.coody.gitee.util.HttpUtil;
import org.coody.gitee.util.HttpUtil.HttpEntity;

public class EmailSendFuzzer extends GiteeFuzzer {



	@Override
	public void fuzzer(GiteeEntity giteeEntity) throws FuzzerException {
 		String postData = MessageFormat.format("email={0}&captcha={1}", giteeEntity.getEmail(), giteeEntity.getImgCode());
		HttpEntity entity = HttpUtil.Post("https://gitee.com/users/email_captcha", postData, "utf-8", giteeEntity.getCookie(),
				giteeEntity.buildHeader());
		if(entity.getCode()!=204) {
			throw new EmailRegisterException("邮件发送失败>>"+giteeEntity.getEmail()+":"+entity.getHtml());
		}
		giteeEntity.setCookie(entity.getCookie());
		System.out.println("发送邮箱验证码>>" + giteeEntity.getEmail());
	}
}
